import React from "react"

class Error extends React.Component {
    state = {
        isError: false,
        errInfo: ""
    }
    static getDerivedStateFromError(error) {
        console.log(error)
        return {
            isError: true,
            errInfo: error
        }
    }
    componentDidCatch(error, errInfo) {
        console.log(error)
        console.log(errInfo)
    }
    render() {
        console.log(this.props)
        if (!this.state.isError) {
            return (
                this.props.children
            )
        } else {
            return <h1>组件加载出错,{this.state.errInfo}</h1>
        }
    }
}
export default Error